﻿
var appConfig = {};
appConfig.toastrTitle = "Smarta.Admin - 提示";  //提示出现的标题
appConfig.lockTime = 0; //锁屏超时时间 默认十五分钟 900 (15min)
appConfig.adminPath = "/Admin/"; //管理目录
appConfig.uploadPath = "/uploads/"; //上传文件的目录
appConfig.AutoSave = false;
appConfig.AutoSaveTime = 60000; //自动保存的时间 单位 : 毫秒
appConfig.AutoSaveName = "AutoSaveContent"; //自动保存的cookie名称
appConfig.IsLinux = true; //linux 用canvas画图 win用第三方dll

//灰度图片 200*150
appConfig.GrayImg = "";


//系统编码字符串 配合后台使用 //如果涉及常用单词都在后面加s以防内容被替换
function StrEnCode(str) {
    str = str + "";
    //str = str.replace(/_FLAG_CONTENT_ENCODE_/g, ""); //替换编码头标示
    str = str.replace(/\[/g, "_MPBRACKETS_").replace(/]/g, "_MNBRACKETS_"); //[]
    str = str.replace(/{/g, "_BPBRACKETS_").replace(/}/g, "_BNBRACKETS_"); //{}
    str = str.replace(/\(/g, "_SPBRACKETS_").replace(/\)/g, "_SNBRACKETS_"); //()
    str = str.replace(/</g, "_TPBRACKETS_").replace(/>/g, "_TNBRACKETS_"); //<>
    str = str.replace(/%/g, "_PERCENTSS_").replace(/&/g, "_ANDS_"); //%&
    str = str.replace(/"/g, "_DOUBLEQUOTES_").replace(/'/g, "_APOSTROPHE_"); //"'
    str = str.replace(/\//g, "_SLASHS_").replace(/\\/g, "_BACKSLASHS_"); // /(斜杠) \反斜杠
    str = str.replace(/:/g, "_COLONS_").replace(/;/g, "_SEMICOLONS_"); // 冒号+分号
    str = str.replace(/\n/g, "_WRAPS_").replace(/\t/g, "_TABSS_").replace(/\r/g, "_ENTERS_").replace(/\r\n/g, "_ENTERSWRAPS_");
    str = str.replace(/©/g, "_COPYRIGHT_").replace(/=/g, "_EQUAL_"); // 版权符号 等于号
    str = str.replace(/\+/g, "_PLUS_").replace(/-/g, "_MINUS_"); //加号减号
    str = str.replace(/\*/g, "_MULTIPLICATION_"); //乘号
    str = str.replace(/\~/g, "_WAVE_").replace(/\!/g, "_SIGH_").replace(/\@/g, "_AITS_").replace(/\#/g, "_WELL_").replace(/\$/g, "_DOLLAR_").replace(/\^/g, "_WORDOFF_");
    return str;
}
//系统解码字符串 配合后台使用
function StrDeCode(str) {
    str = str + "";
    str = str.replace(/_MPBRACKETS_/g, "[").replace(/_MNBRACKETS_/g, "]"); //[]
    str = str.replace(/_BPBRACKETS_/g, "{").replace(/_BNBRACKETS_/g, "}"); //{}
    str = str.replace(/_SPBRACKETS_/g, "(").replace(/_SNBRACKETS_/g, ")"); //()
    str = str.replace(/_TPBRACKETS_/g, "<").replace(/_TNBRACKETS_/g, ">"); //<>
    str = str.replace(/_PERCENTSS_/g, "%").replace(/_ANDS_/g, "&"); //%&
    str = str.replace(/_DOUBLEQUOTES_/g, "\"").replace(/_APOSTROPHE_/g, "'"); //"'
    str = str.replace(/_SLASHS_/g, "/").replace(/_BACKSLASHS_/g, "\\"); // /(斜杠) :冒号  \反斜杠
    str = str.replace(/_COLONS_/g, ":").replace(/_SEMICOLONS_/g, ";"); // 冒号+分号
    str = str.replace(/_WRAPS_/g, "\n").replace(/_TABSS_/g, "\t").replace(/_ENTERS_/g, "\r").replace(/_ENTERSWRAPS_/g, "\r\n");
    str = str.replace(/_COPYRIGHT_/g, "©").replace(/_EQUAL_/g, "=");
    str = str.replace(/_PLUS_/g, "+").replace(/_MINUS_/g, "-");
    str = str.replace(/_MULTIPLICATION_/g, "*");
    str = str.replace(/_WAVE_/g, "~").replace(/_SIGH_/g, "!").replace(/_AITS_/g, "@").replace(/_WELL_/g, "#").replace(/_DOLLAR_/g, "$").replace(/_WORDOFF_/g, "^");
    return str;
}





function alert(msg, callback) {
    if (arguments.length == 1) {
        bootbox.alert(msg.toString());
    } else {
        bootbox.alert(msg.toString(), function () { setTimeout(function () { callback(); }, 300) });
    }
}

/*获取地址栏中的文件夹路径*/
function GetUrlFolderPath() {
    var pathname = location.pathname;
    if (pathname.indexOf('.') > -1) {
        var pn = pathname.split('/');
        return pathname.replace(pn[pn.length - 1], "");
    }
    else {
        if (pathname.substring(pathname.length, pathname.length - 1) == "/") {
            return pathname;
        }
        else {
            return pathname + "/";
        }
    }
}

/*
提示层 默认不传参数为覆盖body
element = 传入的覆盖层 #id .class tagname 形式
*/
function loading(element, msg) {
    if (arguments.length==0) {
        App.blockUI({
            target: 'body',
            boxed: true,
            message: '请稍后...'
        });
    }
    if (arguments.length == 1) {
        App.blockUI({
            target: 'body',
            boxed: true,
            message: arguments[0]
        });
    }
    if (arguments.length == 2) {
        App.blockUI({
            target: arguments[0],
            boxed: true,
            message: arguments[1]
        });
    }
}
function loading_remove() {
    App.unblockUI();
}

function metronicAlerts(msg, type)
{
    if ($(".page-content").length > 0) {
        if (arguments.length == 1) {
            type = "danger";
        }
        var metronicalert = "";
        metronicalert += '<div class="custom-alerts alert alert-' + type + ' fade in">';
        metronicalert += '    <button type="button" class="close" style="margin-top:5px;" data-dismiss="alert" aria-hidden="true"></button>';
        metronicalert += '    <i class="fa-lg fa fa-warning"></i>&nbsp;&nbsp;' + msg;
        metronicalert += '</div>';
        $(".page-content").prepend(metronicalert);
    }
}

/*
调用提示插件
msg = 传入的内容
type = [info,success,error,warning]
*/
function notice(msg, type) {
    if (arguments.length == 1) {
        toastr.info(msg, appConfig.toastrTitle);
    } else {
        switch (type) {
            case "info":
                toastr.info(msg, appConfig.toastrTitle);
                break;
            case "success":
                toastr.success(msg, appConfig.toastrTitle);
                break;
            case "error":
                toastr.error(msg, appConfig.toastrTitle);
                break;
            case "warning":
                toastr.warning(msg, appConfig.toastrTitle);
                break;
            default:
                toastr.info(msg, appConfig.toastrTitle);
                break;
        }
    }
}

/*定时锁屏*/
function lockScreen() {
    if ((window.location.pathname).indexOf("/login.aspx") == -1 && (window.location.pathname).indexOf("/lock.aspx") == -1) {
        if (appConfig.lockTime > 0) {
            setTimeout(function () {
                window.location.href = appConfig.adminPath + "lock.aspx?from=" + encodeURIComponent(window.location.href);
            }, parseInt(appConfig.lockTime * 1000));
        }
    }
}


/*获取QueryString 如果为undefined或者为空 返回空*/
function GetQs(name) {
    var r = QueryString.GetValue(name);
    if (r !== undefined && r != "") {
        return r;
    }
    else {
        return "";
    }
}

//初始化编辑器
function InitUEditor() {
    $('textarea[name=editor]').each(function (i, e) {
        UE.getEditor($(e).attr("Id"));
    });
}

//初始化编辑器
function InitFEditor() {
    //var feditorStr = "<!DOCTYPE html><html><head><meta charset='utf-8'/><meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/><style type='text/css'>html,body{padding:0;margin:1px 1px 1px 1px}</style><link rel='stylesheet' type='text/css' href='/sysres/dist/css/ueditor_iframe.css'/></head><body><div field_type='feditor'></div></body></html><script src='" + appConfig.adminPath + "assets/global/plugins/jquery.min.js' type='text/javascript'><\/script><link rel='stylesheet' href='" + appConfig.adminPath + "assets/feditor/css/loadfeditor.css'/><script type='text/javascript' src='" + appConfig.adminPath + "assets/feditor/js/loadfeditor.js'><\/script><script type='text/javascript'>var editorContent='';InitFeditorFull($('[field_type=feditor]')); function getContent(){return $('[field_type=feditor]').froalaEditor('html.get',true)}; function setContent(cont){if(arguments.length>0){$('[field_type=feditor]').froalaEditor('html.set',cont)}else{$('[field_type=feditor]').froalaEditor('html.set',editorContent)}}setContent();<\/script>";
    //feditorStr = "<iframe style=\"border:none; width:100%; height:590px; \" src=\"javascript:void(function(){ document.open(); document.write(&quot;" + feditorStr + "&quot;); document.close();  }())\"></iframe>";

    //feditorStr = "<script> document.writeln(\"" + feditorStr + "\"); </script>";

    //feditorStr = "<iframe style=\"border:none; width:100%; height:590px; \" src=\"index.aspx\"></iframe>";

    $("div[field_type=feditor]").each(function (i, e) {
        //$(e).html(feditorStr);
        //console.log("初始化feditor", feditorStr);
        InitFeditorIFrameFull($("[field_type='feditor']"));
    });
}


//初始化拖拽
function InitMultipleDrag() {
    if ($('.Multiple-Img').length > 1) {
        $('.Multiple-Img').arrangeable();
    }
}

function IsAddAction(){
    if (GetQs("action").length > 3) {
        if (GetQs("action").substring(0, 3) == "add") {
            return true;
        }
    }
    return false;
}
function IsEditAction() {
    if (GetQs("action").length > 3) {
        if (GetQs("action").substring(0, 4) == "edit") {
            return true;
        }
    }
    return false;
}

/*返回来路页面是不是回收站 , 主要用于从回收站点出去的页面要回到回收站中去*/
function IsFromRecycle() {
    if (document.referrer.search(/\/recycle.aspx?/i) > -1) {
        return true;
    } else {
        return false;
    }
}
function IsRecycle() {
    if (document.location.pathname.search(/\/recycle.aspx/i) > -1) {
        return true;
    } else {
        return false;
    }
}

function InitContentHeight() {
    if (typeof App == "object") {
        var content = $('.page-content');
        var available_height = App.getViewPort().height - $('.page-footer').outerHeight() - $('.page-header').outerHeight();
        if (content.height() < available_height) {
            content.attr('style', 'min-height:' + available_height + 'px');
        }
    }
    else {
       // console.log("App对象未找到");
    }
}

function AutoSave_CookieName() {
    //return window.location.href.replace(/\//g, "_").replace(/:/g, "_").replace(/\?/g, "_").replace(/\&/g, "_").replace(/=/g, "_").replace(/\./g, "_").replace(/_/g, "");
    return GetPageFlag();//appConfig.AutoSaveName;
}

//获取页面标识
function GetPageFlag() {
    return window.location.href.replace(/\//g, "_").replace(/:/g, "_").replace(/\?/g, "_").replace(/\&/g, "_").replace(/=/g, "_").replace(/\./g, "_").replace(/_/g, "");
}

/*CheckBox是否选中状态 传入Jq对象*/
function CheckBox_IsCheck(t) {
    return t.is(':checked');
}
/*CheckBox操作选中 第一个参数是Jq对象 第二个为状态 true false*/
function CheckBox_State(t,s) {
    t.prop("checked", s ? "checked" : "");
}

/*Switch是否选中状态 传入Jq对象*/
function Switch_IsCheck(t) {
    return t.bootstrapSwitch('state');
}
/*Switch操作选中 第一个参数是Jq对象 第二个为状态 true false*/
function Switch_State(t, s) {
    t.bootstrapSwitch('state', s);
}

function Btn_Disabled(t) {
    if (!t.hasClass("disabled")) {
        t.addClass("disabled");
    }
}
function Btn_UnDisabled(t) {
    t.removeClass("disabled");
}

function InitToastr()
{
    if (typeof (toastr) != "undefined") {
        //初始化提示的参数 供notice调用
        toastr.options = {
            "closeButton": true,
            "debug": false,
            "positionClass": "toast-top-right",
            "onclick": null,
            "showDuration": "1000",
            "hideDuration": "1000",
            "timeOut": "3000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        }
    }
}

/*初始化所有的时间选择框*/
function InitDatePicker() {
    if ($('.date-picker').length>0) {
        var myDate = new Date();
        $('.date-picker').datepicker({
            format: 'yyyy-mm-dd ' + $.FormartDate("hh:mm:ss"),
            autoclose: true
        });
    }
}

/*初始化可以选择到分钟的框*/
function InitDatePicker_Minute() {
    if ($('.date-picker-minute').length > 0) {
        //var myDate = new Date();
        $(".date-picker-minute").datetimepicker({
            todayBtn: 1,
            autoclose: 1,
            language: 'zh',
        });
    }
}


//---------------------------------------多图上传插件初始化 Begin
/*编辑图片信息*/
function MultipleImgEditInfo(context, i, field) {
    //console.log("编辑方法",i, field);
    //console.log(context);
    //console.log($("#multiple-upload-dialog-Photo .green").length);
    //获取信息填充
    $("#multiple-upload-dialog-" + field + " .modal-title").text("编辑第 " + (i + 1) + " 张图片信息");
    $(".multiple-img-title-" + field).val($(".Multiple_" + field + " .Multiple-Img").eq(i).find("img").attr("title"));
    //替换换行符
    var desc = v = $(".Multiple_" + field + " .Multiple-Img").eq(i).find("img").attr("desc");
    desc = desc.replace(/<br\/>/g, "\n");
    //替换换行符结束
    $(".multiple-img-desc-" + field).val(desc);
    //$(".multiple-img-desc-" + field).val($(".Multiple_" + field + " .Multiple-Img").eq(i).find("img").attr("desc"));
    //console.log($("#multiple-upload-dialog-" + field + " .green"));
    $("#multiple-upload-dialog-" + field + " .green").one("click", function () {
        //console.warn("点击事件", i, field);
        //console.log($(".multiple-img-title-" + field).val(), $(".multiple-img-desc-" + field).val());
        $(".Multiple_" + field + " .Multiple-Img").eq(i).find("img").attr("title", $(".multiple-img-title-" + field).val());
        $(".Multiple_" + field + " .Multiple-Img").eq(i).find("img").attr("desc", $(".multiple-img-desc-" + field).val());
        $("#multiple-upload-dialog-" + field).modal('hide');
    });
    $("#multiple-upload-dialog-" + field + " .default").one("click", function () {
        $("#multiple-upload-dialog-" + field + " .green").unbind("click");
        $("#multiple-upload-dialog-" + field).modal('hide');
    });
    $("#multiple-upload-dialog-" + field).modal('show');
}

/*右键菜单上的操作*/
function ContextMenuItemClick(context, i, action, field) {
    if (action === "edit") {
        MultipleImgEditInfo(context, i, field);
    }
    if (action === "delete") {
        $(context).fadeOut(300, function () {
            $(this).remove();
        });
    }
}

/*初始化页面上的所有多图上传的右键菜单*/
function InitContextMenu() {
    if ($("div[field_type='multipleimgupload']").length > 0) {
        $("div[field_type='multipleimgupload']").each(function (i, ele) {
            if ($(ele).children(".Multiple-Img").length > 0) {
                $(ele).children(".Multiple-Img").contextmenu({
                    target: '#multiple-upload-context-menu-' + $(ele).attr("field"),
                    onItem: function (context, e) {
                        //执行点击事件
                        //console.log("右键菜单",context.index(), $(e.currentTarget).attr("data-action"), $(ele).attr("field"));
                        ContextMenuItemClick(context, context.index(), $(e.currentTarget).attr("data-action"), $(ele).attr("field"));
                        //console.log(context, context.index(), $(e.currentTarget).attr("data-action"));
                    }
                });
            }
        });
    }
}

/*组合上传完成的图片*/
function MakeMultipleImg(src) {
    var MultipleImg = "";
    MultipleImg += "<div class=\"Multiple-Img thumbnail\" data-toggle=\"context\" data-target=\"#context-menu\" >";
    MultipleImg += "<span style=\"background-image:url(" + src + ")\">";
    MultipleImg += "<img src=" + src + " title=\"\" desc=\"\">";
    MultipleImg += "</span>";
    MultipleImg += "</div>";
    return MultipleImg;
}

/*初始化多图上传按钮 , 此按钮只可初始化一次否则会多次调用*/
function InitMultipleImgUploadBtn() {
    if ($("input[rel='Multiple-Img-Upload']").length > 0) {
        $("input[rel='Multiple-Img-Upload']").each(function (i, ele) {
            $(ele).Uploads({
                url: appConfig.adminPath + "ashx/upload.ashx",
                process: function (process, i, fileList, field) {
                    $(".Multiple-UploadTips-" + field + " .progress-bar").css("width", process + "%");
                    $(".Multiple-UploadTips-" + field + " .status-number").html(process + "%");
                    $(".Multiple-UploadTips-" + field + " .status-title").html(i + "/" + fileList.length);
                    $(".Multiple-UploadTips-" + field + " small").text(fileList[i - 1].name);
                },
                success: function (flag, val, i, field) {
                    //console.log(flag, val, i, field);
                    if (flag) {
                        InitMultipleDrag();
                        InitContextMenu();
                    }
                    else {
                        var uploadRes = JSON.parse(val);
                        if (uploadRes.state == "success") {
                            $(".Multiple_" + field).prepend(MakeMultipleImg(uploadRes.link));
                        }
                        else {
                            notice("您上传第 " + (i + 1) + " 张图片 , 由于 \"" + uploadRes.msg + "\" 原因 , 上传失败 , 系统已自动跳过该文件", "error");
                        }

                    }
                },
                before: function (fileList, field) {
                    $(".Multiple-UploadTips-" + field).show();
                },
                complate: function (field) {
                    setTimeout(function () {
                        $(".Multiple-UploadTips-" + field).fadeOut(500);
                    }, 1000);
                }
            });

        })
    }
}
//---------------------------------------多图上传插件初始化 End

//---------------------------------------单图片上传初始化 Begin
function InitSingleImgUpload() {
    if ($("input[field_type='imgupload']").length > 0) {
        $("input[field_type='imgupload']").each(function (i, ele) {
            $(ele).Uploads({
                url: appConfig.adminPath + "ashx/upload.ashx",
                process: function (process, i, fileList, field) {
                    $(".Image-Upload-Tip-" + field).html(" " + process + "% ");
                },
                success: function (flag, val, i, field) {
                    //console.log(flag, val, i, field);
                    if (flag) {
                        var uploadRes = val[i - 1];
                        uploadRes = JSON.parse(uploadRes);
                        if (uploadRes.state == "success") {
                            $("input[field='" + field + "']").attr("data-value", uploadRes.link);
                            $("input[name=imgsrc_" + field + "]").val(uploadRes.link);
                            //$("input[field='" + field + "']").attr("data-value", val[i - 1]);
                            //$("input[name=imgsrc_" + field + "]").val(val[i - 1]);
                        }
                        else {
                            alert(uploadRes.msg);
                        }
                    }
                },
                before: function (fileList, field) {
                    $(".Image-Upload-Tip-" + field).html(" 0% ");
                    $(".Image-Upload-Tip-" + field).show();
                },
                complate: function (field) {
                    setTimeout(function () {
                        $(".Image-Upload-Tip-" + field).fadeOut(500);
                    }, 1000);
                }
            });
        })
    }
}
//---------------------------------------单图片上传初始化 End

//---------------------------------------单文件上传初始化 Begin
function InitSingleFileUpload()
{
    if ($("input[field_type='fileupload']").length > 0) {
        $("input[field_type='fileupload']").each(function (i, ele) {
            $(ele).Uploads({
                url: appConfig.adminPath + "ashx/upload.ashx?t=file",
                process: function (process, i, fileList, field) {
                    $(".File-Upload-Tip-" + field).text(" " + process + "% ");
                },
                success: function (flag, val, i, field) {
                    if (flag) {
                        var uploadRes = val[i - 1];
                        uploadRes = JSON.parse(uploadRes);
                        if (uploadRes.state == "success") {
                            $("input[field='" + field + "']").attr("data-value", uploadRes.link);
                            $("input[name=filesrc_" + field + "]").val(uploadRes.link);
                            //$("input[field='" + field + "']").attr("data-value", val[i - 1]);
                            //$("input[name='filesrc_" + field + "']").val(val[i - 1]);
                        }
                        else {
                            alert(uploadRes.msg);
                        }
                    }
                },
                before: function (fileList, field) {
                    $(".File-Upload-Tip-" + field).text(" 0% ");
                    $(".File-Upload-Tip-" + field).css("visibility", "visible");
                },
                complate: function (field) {
                    setTimeout(function () {
                        $(".File-Upload-Tip-" + field).css("visibility", "hidden");//.fadeOut(500);
                    }, 1000);
                }
            });
        })
    }
}
//---------------------------------------单图片上传初始化 End


//将没有权限的栏目移除掉
function RemoveNoRoleChannel()
{
    $(".left-menu-item .norole").remove();

    if ($(".left-menu-item .systemPageList").length == 0) {
        $(".left-menu-item .systemPageFlag").remove();
    }

}

//后台处理当前选中状态
function curLeftMenu()
{
    var classid = GetQs("classid");
    if (classid != "") {  //栏目页
        $("[data-classid='" + classid + "']").addClass("active");
        //$($("#divId").children("div").get(0))

        var parents_list = $("[data-classid='" + classid + "']").parents(".nav-item");
        var curParent = $(parents_list[parents_list.length - 1]);
        curParent.addClass("active open");
        curParent.children("a").eq(0).append($('<span class="selected"></span>'));

        var sub_menus = $("[data-classid='" + classid + "']").parents(".sub-menu");
        sub_menus.css("display", "block");
        parents_list.find("span.arrow").addClass("open");
    }
    else {
        //系统页

        var table = GetQs("t");
        var curItem = $("[data-table='" + table + "']");
        curItem.closest(".nav-item").addClass("active");


        var parents_list = curItem.parents(".nav-item");
        var curParent = $(parents_list[parents_list.length - 1]);
        curParent.addClass("active open");
        curParent.children("a").eq(0).append($('<span class="selected"></span>'));
        
        var sub_menus = $("[data-classid='" + classid + "']").parents(".sub-menu");
        sub_menus.css("display", "block");
        parents_list.find("span.arrow").addClass("open");
        

    }
    

}

function InitSelect2() {
    $("select").on("select2:select", function (evt) {
        var element = evt.params.data.element;
        var $element = $(element);

        $element.detach();
        $(this).append($element);
        $(this).trigger("change");
    });

    $("select").on("select2:unselect", function (evt) {
        var element = evt.params.data.element;
        var $element = $(element);
        //$element.remove();
        
        //var element = evt.params.data.element;
        //var $element = $(element);
        //$element.detach();
        //$(this).append($element);
    });
}

//显示时间
function ShowDateTime()
{
    if ($(".curtime").length > 0) {
        setInterval(function () {
            $(".curtime").text($.FormartDate("yyyy-MM-dd hh:mm:ss"))
        }, 1000);
    }
}



$(function () {
    //事件都写在里面
    
    //系统时间
    ShowDateTime();
    //提示浏览器版本过低
    //if ($.IEVersion()<=10) {
    //    metronicAlerts("您正在使用较低版本的浏览器，为了保证后台功能正常使用以及良好的操作体验，建议您升级浏览器至最新版本（或更换为Chrome、360急速浏览器、FireFox、Opera等更为先进的浏览器）。");
    //}

    //后台处理当前选中状态
    curLeftMenu();
    //锁屏事件
    lockScreen();
    //初始化提示插件
    InitToastr();
    //日期插件
    InitDatePicker();

    InitDatePicker_Minute();

    //初始化编辑器
    InitUEditor();
    //初始化F编辑器
    InitFEditor();
    //多图拖拽事件
    InitMultipleDrag();

    //---------------------------------------多图上传插件初始化 Begin
    InitContextMenu();
    InitMultipleImgUploadBtn();
    //---------------------------------------多图上传插件初始化 End
    InitSingleImgUpload();
    InitSingleFileUpload();

    //窗口改变大小的时候执行的事件
    window.onresize = debounce(function () {
        InitContentHeight();
    }, 300, false)

    //页面初始化大小
    InitContentHeight();

    //去除没有权限的栏目
    RemoveNoRoleChannel();

    //如果是添加  将所有开关切换到关闭状态 , 时间设置到默认时间
    if (IsAddAction()) {
        $(".make-switch").each(function (i, e) {
            if ($(this).is(':checked') == false) {
                Switch_State($(this), false);
            }
        });
        $(".date-picker").each(function (i, e) {
            $(this).val($.FormartDate());
        });
    }

    //初始化Select2
    InitSelect2();
    
    //验证码
    $(".verifyCode_Img").attr("src", $(".verifyCode_Img").attr("_src"));
    //验证码点击更换
    $(".verifyCode_Img").on("click", function () {
        var src = $(this).attr("_src");
        $(this).attr("src", src + ((src.indexOf('?') > -1) ? "&" : "?") + "t=" + Math.random());
    });

    ///用于设置某个字段的默认值 , 点击直接赋值的那种
    $(".setDefaultValue").on("click", function () {
        var setField = $(this).attr("setField");
        var setValue = $(this).attr("setValue");
        //var setType = $(this).attr("setType"); //设置类型 , 暂时只有input
        var setObj;
        if (setField === undefined) {
            setObj = $(this).parent().prev();
        } else {
            setObj = $("[field='" + setField + "']");
        }

        if (setValue === undefined) {
            setValue = $(this).html();
        }
        if (setObj.attr("disabled") == "disabled") {
            return false;
        }
        setObj.val(setValue).blur();
        //var obj = $(this).parent().prev().val($(this).html());
    });

    //所有的后台列表全选事件
    //全选规则 权限按钮(.check-all) 按钮的rel标识需要全选的选中框
    $(".check-all").on("click", function () {
        var _this = $(this);
        var state = _this.attr("check");
        //已经全选
        if (state == 'true') {
            CheckBox_State($("." + _this.attr("rel")), false);
            _this.find("span").text("全选");
            _this.attr("check",'false');
        }
        //没有全选
        if (state == 'false') {
            CheckBox_State($("." + _this.attr("rel")), true);
            _this.find("span").text("取消");
            _this.attr("check", 'true');
        }
    });

    //---------------------------------------文件填写路径和清除按钮 Begin
    //文件上传的清除按钮
    $(".fileupload-clear").on("click", function () {
        var field = $(this).attr("name").split("_")[1];
        $("[field='" + field + "']").attr("data-value", "");
        $("[name='filesrc_" + field + "']").val("");
    });
    //文件填写路径
    $(".filesrc").on("input propertychange", function () {
        var val = $(this).val();
        var field = $(this).attr("name").split("_")[1];
        $("[field='" + field + "']").attr("data-value", val);
    });
    //---------------------------------------文件填写路径和清除按钮 End


    //---------------------------------------图片填写路径和清除按钮 Begin
    //图片上传的清除按钮
    $(".imgupload-clear").on("click", function () {
        var field = $(this).attr("name").split("_")[1];
        $("[field='" + field + "']").attr("data-value", "");
        $("[name='imgsrc_" + field + "']").val("");
        var parent = $(this).closest(".fileinput");
        var imgs = parent.find("img");
        imgs.each(function (i, e) {
            $(e).attr("src", appConfig.GrayImg);
        });
    });
    //图片填写路径
    $(".imgsrc").on("input propertychange", function () {
        var val = $(this).val();
        var field = $(this).attr("name").split("_")[1];
        $("[field='" + field + "']").attr("data-value", val);
        var parent = $(this).closest(".fileinput");
        var imgs = parent.find("img");
        imgs.each(function (i, e) {
            $(e).attr("src", val);
        });
    });
    //---------------------------------------图片填写路径和清除按钮 End


    //---------------------------------------密码框按钮显示密码 Begin
    $(".password_eye").on("mousedown", function () {
        var field = $(this).attr("eye");
        $("input[field='" + field + "']").attr("type", "text");
    });
    $(".password_eye").on("mouseup", function () {
        var field = $(this).attr("eye");
        $("input[field='" + field + "']").attr("type", "password");
    });
    //---------------------------------------密码框按钮显示密码 End


    //---------------------------------------列表/回收站页的搜索 Begin
    //列表页的搜索
    $("#manager-list-search").submit(function () {
        var key = $("#manager-list-search input[name=key]").val();
        if (key != "") {
            window.location.href = window.location.pathname + "?t=" + QueryString.GetValue("t") + (QueryString.GetValue("classid") === undefined ? "" : "&classid=" + QueryString.GetValue("classid")) + "&key=" + key;
        }
        return false;
    });
    //搜索框的x按钮
    $(".remove-search").on("click", function () {
        var key = $("#manager-list-search input[name=key]").val();
        if (key != "") {
            window.location.href = window.location.pathname + "?t=" + QueryString.GetValue("t") + (QueryString.GetValue("classid") === undefined ? "" : "&classid=" + QueryString.GetValue("classid"));
        }
    });
    //---------------------------------------列表/回收站页的搜索 End

});

//$('.make-switch').bootstrapSwitch({
//    onSwitchChange: function (event, state) {
//        if (state == true) {
//            alert(1);
//        } else {
//            alert(2);
//        }
//    }
//});